package com.qian.ddj.pay.controller;

import com.qian.api.ddj.service.IBusinessService;
import com.qian.api.ddj.util.SignUtils;
import com.qian.ddj.pay.model.Close;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/other")
public class OtherController {

    @Autowired
    private IBusinessService businessService;

    private String key = "BLhOMfb8THVuQDYliSzvRDyBQ47jE63p";

    @PostMapping("/closeChannel")
    public String closeChannel(Close close) {
        Map<String, String> map = new HashMap<>();
        map.put("id", close.getId().toString());
        map.put("sign", close.getSign());
        if (SignUtils.verifySign(map, key)) {
            List<Integer> businessIds = new ArrayList<>();
            businessIds.add(close.getId());
            businessService.stop(businessIds);
            return "Success";
        }
        return "Fail";
    }
}
